package com.it.you.base.bigdecimal;

import com.it.you.pojo.ItemInfo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class BigDecimalTest2 {

    public static void main(String[] args) {
        List<ItemInfo> list = new ArrayList<>();

        ItemInfo itemInfo1 = new ItemInfo(new BigDecimal(3),new BigDecimal(4), 2, "泡面");
        ItemInfo itemInfo2 = new ItemInfo(new BigDecimal(6),new BigDecimal(8), 3, "香肠");
        list.add(itemInfo1);
        list.add(itemInfo2);
        //累加统计
        BigDecimal activityTotalPrice = list.stream().map(w -> w.getActivityPrice().multiply(new BigDecimal(w.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
        System.out.println(activityTotalPrice);

        BigDecimal memberTotalPrice = list.stream().map(w -> w.getMemberPrice().multiply(new BigDecimal(w.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
        System.out.println(memberTotalPrice);

        if (activityTotalPrice.compareTo(memberTotalPrice) > 0) {
            System.out.println("套餐价格设置不合理");
        } else {
            System.out.println("套餐价格设置合理");
        }
    }
}
